
#ifndef _SC_GUI_H
#define _SC_GUI_H

#include "lvgl.h"
#include "sc_lcd.h"
#include "sc_arc.h"
#include "sc_event_task.h"



#define sc_abs(a) ((a<0)?(-a):(a))
#define SC_MAX(a,b)(a>b?a:b)
#define SC_MIN(a,b)(a<b?a:b)

/**fun: pfb画点*/
#define set_pixel_value(dest, offs, src,  c)   dest->buf[offs]=alphaBlend(c,dest->buf[offs],src)


typedef struct
{
    const uint8_t *map;
    uint16_t w;
    uint16_t h;
} SC_img_t;

typedef struct
{
    const uint8_t *map;
    uint32_t   len;
    uint16_t w;
    uint16_t h;
} SC_img_zip;



typedef enum
{
    STR_ALIGN_LEFT   =   0x01,   //左对齐
    STR_ALIGN_RIGHT  =   0x02,   //右对齐
    STR_ALIGN_CENTER =   0x03,   //居中齐

    STR_SHOW_BORDER  =   0x04,    //显示方形框
    STR_SHOW_BORDER2  =  0x08,    //显示圆色框

}LABEL_ALIGN;

typedef struct
{
    SC_ARER         box;
    LABEL_ALIGN     align;
    const char     *str;
} SC_label;

typedef struct
{
   // uint16_t    state;
    uint16_t    alpha;      //全局透明度
    uint16_t    bkc;         //主题底色
    uint16_t    bc;          //背影色
    uint16_t    fc;          //前影色

    uint16_t    dma_i;
    uint16_t    *dma_prt;
    uint16_t    *pfb_buf;

    void         *font;           //字体
    SC_ARER      lcd_area;

    void       (*bsp_pset)(int,int,uint16_t);
    void       (*Refresh)(int xs, int ys,uint16_t w, uint16_t h,uint16_t *buf);
} SC_GUI;

extern SC_GUI *gui;


uint16_t alphaBlend( uint16_t fc, uint16_t bc,uint8_t alpha);

void SC_GUI_Init( void (*bsp_pset)(int,int,uint16_t),uint16_t bkc,uint16_t bc,uint16_t fc, void* font);

void SC_Clear(int xs,int ys,int xe,int ye);

void SC_pfb_Image(SC_tile *dest,int xs,int ys,SC_img_t *src);

void SC_pfb_DrawFill(SC_tile *dest,int xs,int ys,int xe,int ye,uint16_t fc);

void SC_pfb_DrawFrame(SC_tile *dest, int xs, int ys, int xe, int ye,uint16_t fc);

int SC_pfb_printf(SC_tile *dest, int x,int y,const char* txt,uint16_t fc,uint16_t bc, lv_font_t* font);

void SC_set_label(SC_label *label,int xs,int ys,int w,int h,const char *str,LABEL_ALIGN align);

int SC_pfb_label(SC_tile *dest,SC_label *label,int xofs,int yofs,uint16_t fc,uint16_t bc,lv_font_t* font);


void  SC_pfb_chart(SC_tile *dest,SC_tile* chart,int xd,int yd,int16_t vol,uint16_t fc,uint16_t gc);


void SC_GUI_test(void);
#endif
